package Text_61;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class Code {

	public static void main(String[] args) {
		 
		//升序排列
        TreeMap<Integer,String> tm = new TreeMap<>();
        tm.put(6,"康师傅");
        tm.put(4,"王老吉");
        tm.put(5,"王哈哈");
        tm.put(2,"农夫山泉");
        System.out.println(tm);
        System.out.println("===================");
        //降序排列
        TreeMap<Integer,String> tm1 = new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        tm1.put(6,"康师傅");
        tm1.put(4,"王老吉");
        tm1.put(5,"王哈哈");
        tm1.put(2,"农夫山泉");
        System.out.println(tm1);
        System.out.println("=================");
        for(Map.Entry<Integer,String> entry:tm1.entrySet()){
            int key = entry.getKey();
            String value = entry.getValue();
            System.out.print(key+"="+value+" ");
        }

	}

}
